package com.ruoyi.coal.modules.coal.service.impl;

import com.ruoyi.coal.modules.coal.service.StartRadarService;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import org.springframework.stereotype.Service;

@Service
public class StartRadarServiceImpl implements StartRadarService {
    public String[] startRadar() {
        StringBuilder msg = null;
        try {
            String ip = "172.16.102.51";
            int port = 50007;
            Socket client = new Socket(ip, port);
            OutputStreamWriter os = new OutputStreamWriter(client.getOutputStream());
            os.write("startRadar");
            os.flush();
            InputStream is = client.getInputStream();
            byte[] buf = new byte[8192];
            msg = new StringBuilder();
            int len;
            for (len = is.read(buf); len > 0; len = is.read(buf))
                msg.append(new String(buf, 0, len));
            client.shutdownInput();
            System.out.println("正在接受回复信息...");
            System.out.println("服务器返回信息：" + msg);
            System.out.println("接收回复信息完成");
                    client.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] split = msg.toString().split(",");
        return split;
    }
}

